<template>
  <div>
    <!--   工作日历 -->
    <el-row type="flex" justify="end">
      <el-select style="width:120px" v-model="currentYear" @change="changeDate">
        <el-option
          v-for="item in yearList"
          :key="item"
          :label="item"
          :value="item"
        >
        </el-option>
      </el-select>
      <el-select
        @change="changeDate"
        style="width:120px; margin-left:15px"
        v-model="currentMonth"
      >
        <el-option
          v-for="item in 12"
          :key="item"
          :label="item"
          :value="item"
        ></el-option>
      </el-select>
    </el-row>
    <el-calendar v-model="currentDate">
      <template slot="dateCell" slot-scope="{ date }">
        <div class="date-content">
          <span class="text">{{ date.getDate() }}</span>
          <span class="rest" v-if="isWeek(date)">休 </span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  created () {
    //   获取当前的年
    let year = this.currentDate.getFullYear()
    //   年
    this.currentYear = year
    //   月
    this.currentMonth = this.currentDate.getMonth() + 1
    //   遍历得到前五年 后五年
    for (let i = year - 5; i <= year + 5; i++) {
      this.yearList.push(i)
    }
  },
  data () {
    return {
      currentDate: new Date(),
      yearList: [], //年份的数组
      currentYear: null, // 年
      currentMonth: null //月
    }
  },
  methods: {
    changeDate () {
      //点击年份和月份变化到最新的日期
      this.currentDate = new Date(`${this.currentYear}-${this.currentMonth}-01`)
    },
    isWeek (date) {
      // 判断是不是周六和周日 周六和周日显示休
      return date.getDay() == 6 || date.getDay() == 0
    }
  }
}
</script>

<style scoped>
::v-deep .el-calendar-day {
  height: auto;
}
::v-deep .el-calendar-table__row td,
::v-deep .el-calendar-table tr td:first-child,
::v-deep .el-calendar-table__row td.prev {
  border: none;
}
.date-content {
  text-align: center;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
::v-deep .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}
::v-deep .el-calendar__header {
  display: none;
}
</style>
